home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT18.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.9 KB  |  110 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 18                         
  5.                                                                               
  6.  This program shows how to make animation with two screens.                   
  7.                                                                               
  8.  One way to produce animation is to use two screens.  One screen is           
  9.  constantly displayed while you draw things on the other.  Once the           
  10.  drawing is complete, you then copy the whole screen in the background        
  11.  to the one that is being displayed.                                          
  12.                                                                               
  13.                                                                               
  14.             Visual Screen                          Background Screen          
  15.      ..............................          ..............................   
  16.      ......o.......................          ......o..............o........   
  17.      ...../Y\......................          ...../Y\............/Y\.......   
  18.      ......|.......................          ......|..............|........   
  19.      ...../.\......................          ...../.\............/.\.......   
  20.      ..............................          ..............................   
  21.      ..............................          .Pos 1-> Clear Screen ->Pos 2.   
  22.      ..............................          ..............................   
  23.                                                                               
  24.  Here we have a person shown on the visual page. It has just been copied      
  25.  over from the background screen. Now you must clear the background screen    
  26.  somehow (put a picture over top, or wcls(0) it).  Once it is cleared, you    
  27.  can use wputblock to show the person in a different place on the screen.     
  28.  Then you copy the background screen to the visual screen and repeat the      
  29.  process.  This method is slow, but can be sped up by decreasing the number   
  30.  of wputblocks you use as sprites, and make the area copied from one screen   
  31.  to another smaller.                                                          
  32.                                                                               
  33.   *** PROJECT ***                                                             
  34.   This program requires the file WGT5_WC.LIB to be linked.                    
  35.                                                                               
  36.   *** DATA FILES ***                                                          
  37.   NONE                                                                        
  38.                                                            WATCOM C++ VERSION 
  39. ==============================================================================
  40. */
  41.  
  42. #include <wgt5.h>
  43.  
  44.  
  45. void main(void)
  46. {
  47.   block screen1;  /* one virtual screen */
  48.   block circ[4];  /* and four circle images */
  49.   short oldmode;
  50.   short y;
  51.  
  52.   if ( !vgadetected () )
  53.   {
  54.     printf("Error - VGA card required for any WGT program.\n");
  55.     exit (0);
  56.   }
  57.   printf ("WGT Example #18\n\n");
  58.   printf ("This program will manipulate 4 bitmaps based on mouse movements.\n");
  59.   printf ("It uses virtual screen buffers to produce smooth results. Press any mouse\n");
  60.   printf ("button to end the demo.\n");
  61.   printf ("\n\nPress any key to continue.\n");
  62.   getch ();
  63.  
  64.   oldmode = wgetmode ();
  65.   vga256 ();
  66.  
  67.   screen1 = wnewblock (0, 0, 319, 199);
  68.  
  69.   for (y = 0; y < 4; y++)
  70.   {
  71.     wsetcolor (40 + y * 5);
  72.     wfill_circle (30, 30, 20 + y * 4);  /* draw a circle with a box cut out in middle */
  73.     /* Note that the circle turns into a square when we increase the radius
  74.        because I'm still grabbing the same area from the wnewblock... */
  75.  
  76.     wsetcolor (0);
  77.     wbar (20, 20, 40, 40);
  78.     circ[y] = wnewblock (10, 10, 50, 50);  /* get the sprite */
  79.   }
  80.  
  81.   wsetscreen (screen1);
  82.   minit ();
  83.  
  84.   do {
  85.     for (y = 0; y < 200; y++)
  86.     {
  87.       wsetcolor (y);
  88.       wline (0, y, 319, y);  /* clear the screen by drawing horz lines (fast) */
  89.     }
  90.  
  91.     wputblock (mouse.mx, mouse.my, circ[0], 1);
  92.     wputblock (279 - mouse.mx, mouse.my, circ[1], 1);
  93.     wputblock (mouse.mx, 159 - mouse.my, circ[2], 1);
  94.     wputblock (279 - mouse.mx, 159 - mouse.my, circ[3], 1);
  95.     /* Put four blocks on the screen depending on where the mouse is. */
  96.     /* The first one displayed is the one in the back. */
  97.  
  98.     wcopyscreen (0, 0, 319, 199, screen1, 0, 0, NULL);  
  99.     /* copy the whole screen */
  100.     /* notice how we never use wnormscreen at all! */
  101.  
  102.   } while (mouse.but == 0);
  103.   mdeinit ();                   /* Deinitialize the mouse handler */
  104.  
  105.   wfreeblock (screen1);
  106.   for (y = 0; y < 4; y ++)
  107.     wfreeblock (circ[y]);
  108.   wsetmode (oldmode);
  109. }
  110.